package ferp.android.social.twvk.vk;

import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import com.perm.kate.api.Auth;
import ferp.android.social.twvk.Account;
import ferp.android.social.twvk.LoginActivity;

/**
 * User: olegs
 * Date: 5/14/13 9:57 AM
 */
public class VkLoginActivity extends LoginActivity
{
  @Override
  protected void handleCookie()
  {
    // otherwise CookieManager will fall with java.lang.IllegalStateException: CookieSyncManager::createInstance() needs to be called before CookieSyncManager::getInstance()
    CookieSyncManager.createInstance(this);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
  }

  @Override
  protected String getTag()
  {
    return VkConnector.TAG;
  }

  @Override
  protected String getAuthUrl()
  {
    return Auth.getUrl(VkConnector.API_ID, Auth.getSettings());
  }

  @Override
  protected Account parseRedirectUrl(String url) throws Exception
  {
    String[] auth = Auth.parseRedirectUrl(url);

    return new Account(auth[0], auth[1]);
  }

  @Override
  protected String getUrlPrefix()
  {
    return Auth.redirect_url;
  }
}
